/*
 * DoName.h
 *
 *  Created on: Oct 18, 2012
 *      Author: wtao
 */

#ifndef DONAME_H_
#define DONAME_H_

#include "_DoObject.h"
#ifdef WIN32
#include <functional> 
#else
#include <backward/hash_fun.h>
#endif

class DoName: public _DoObject
{
protected:
	DoName& operator=(const DoName&);

	bool mLiteral;
	
	virtual CRefPtr< _DoObject > clone() {
		DoName *p0 = new DoName();
		_DoObject::clone(p0, this);
		
		p0->mLiteral = !executable();
		
		return CRefPtr< _DoObject >(p0);
	}
public:
	DoName();
	DoName(const char *str);
	virtual ~DoName();

	DoName(const DoName& name) : _DoObject(){
		mText = name.mText;
		mLiteral = name.mLiteral;
	}

	// hash code gen
    long operator()(CRefPtr< _DoObject > key) const{
    	if (key->type() != eName)
    		CXXTHROW

#ifdef WIN32
		return (long)(std::hash< const char *>()(key->getText()));
#else
		__gnu_cxx::hash<const char *> v;
    	return v(key->getText());
#endif
	}

	void parse(const std::string & str);

	virtual bool executable() const {
		return !mLiteral;
	}
	
	virtual void execute(DevilSemantic &semantic);
	
	virtual bool equals(CRefPtr< _DoObject > obj) {
		return mText.compare(obj->getText()) == 0;
	}
};

#endif /* DONAME_H_ */
